<?php

require_rewrite(MODULE_ROOT . "manager/admin/LogManager.class.php");

class WebDominController extends BaseController {

    private $method;

    public function __construct() {
        parent::__construct();
        $this->method = Handler_http::getMethod();
    }

    public function config() {
        header("Content-type:text/html;charset=utf-8");
        $this->tpl->assign('httpUrl', HTTPFILEURL);
        $this->tpl->display("webdomin/config.html");
    }

    public function configAction() {
        $siteHeader = $_POST['siteHeader'];
        if (!preg_match("/^(?:(https|http):\/\/)?[0-9a-zA-Z]+\.[0-9a-zA-Z]+_?[0-9a-zA-Z]+\.(?:com(?:.cn)?|net|org|info|mobi)$/", $siteHeader)) {
            $msg = '请输入正确格式的域名！';
        } else {
            $manager = new sysadminManager();
            $msg = $manager->writeDomainConfigFile($siteHeader);
            $log_id = LogManager::writeAdminModifyLog($this->user['id'], $this->user['username'], '修改网站域名成功');
            LogManager::writeAuditLog($this->user['id'], $this->user['username'], $log_id, 4, 2);
        }

        Handler_tool::alertAndRedirect($msg, HTTPFILEURL . '/webDomin/config/');
    }

}
